package com.elin4it.blog.controller.manage;

import com.elin4it.blog.pojo.ArticleType;
import com.elin4it.blog.service.ArticleTypeService;
import com.elin4it.blog.service.ConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * User:Elin
 * Date:2015/8/31
 * Description:
 */
@Controller
@RequestMapping("/typeManage")
public class TypeManageController {
    @Autowired
    private ArticleTypeService articleTypeService;
    @Autowired
    private ConfigService configService;

    private final String rootDir = "type/";
    private final String flag = "manage";

    @ModelAttribute
    public void commonMessage(ModelMap map) throws Exception {
        //得到标题和副标题
        String title = configService.findTitle();
        String subTitle = configService.findSubTitle();

        //把标题和副标题放入到model中
        map.put("title", title);
        map.put("subtitle", subTitle);
        //设置页面标识
        map.put("flag", flag);
    }

    @RequestMapping("/allType")
    public String allType(ModelMap modelMap) throws Exception {

        List<ArticleType> articleTypeList = articleTypeService.findArticleTypeList();
        modelMap.put("typeList", articleTypeList);

        return rootDir + "allType";
    }

}
